const fs = require('fs');
const path = require('path');

function traverseFolder(folderPath) {
    const files = fs.readdirSync(folderPath);
    files.forEach(file => {
        const filePath = path.join(folderPath, file);
        const stat = fs.statSync(filePath);
        if (stat.isDirectory()) {
            traverseFolder(filePath); // 递归遍历子文件夹
        } else {
            totalCount++
            if (file.indexOf('指南') === -1) {
                fs.unlinkSync(filePath, (err) => {
                    if (err) {
                        console.log('Error deleting file:', filePath, err);
                    } else {
                        deleteCount++
                    }
                });
            } else {
                guidelineTotalCount++
            }
        }
    });
}
let guidelineTotalCount = 0, totalCount = 0, deleteCount = 0
traverseFolder('D:\\Doc\\may\\指南材料\\指南-需要处理');
console.log(`文献总数为${totalCount}篇，其中指南为${guidelineTotalCount}篇，删除非指南${deleteCount}篇`);
